package com.inctech.controller.navigation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.inctech.model.DocumentEntity;
import com.inctech.service.IDocumentService;

@Controller
@RequestMapping("/navi")
public class NavigationController {
	private final Logger logger = LoggerFactory.getLogger(DocumentEntity.class);
	@Resource(name = "documentService")
	private IDocumentService documentService;
	
	@RequestMapping("/about")
    public String about()
    {
        return "navigation/about";
    }

	@RequestMapping("/contact")
    public String contact()
    {
		return "navigation/contact";
    }

	@RequestMapping("/product")
    public String product()
    {
		return "navigation/product";
    }

	@RequestMapping("/news")
	public String news()
    {
		return "navigation/news";
    }

	@RequestMapping("/prize")
    public String prize()
    {
        return "navigation/prize";
    }

	@RequestMapping("/download")
    public String download()
    {
    	return "navigation/download";
    }
	
	@RequestMapping("/doc")
    public String document()
    {
    	return "navigation/document";
    }
	
	@ResponseBody
	@RequestMapping("/getAllDoc")
	public String getAllDoc(int page, int rows){
		JSONObject obj = new JSONObject();
		//当为缺省值的时候进行赋值
        int currentpage = ( page == 0) ? 1: page;	//第几页
        int pagesize = (rows == 0) ? 10: rows;	//每页显示数量
        int index = (currentpage - 1) * pagesize;	//从第几条开始显示
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("index", index);
        params.put("pagesize", pagesize);
		try {
			List<DocumentEntity> list = documentService.queryAll(params);
			int total = documentService.getTotalCount();
			obj.put("total", total);
			obj.put("rows", list);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("出错了", e);
		}
		
		return obj.toString();
	}
}
